package com.loveprogrammer.model.game;

import com.loveprogrammer.dto.battle.BattleFightResult;
import com.loveprogrammer.model.Hero;
import lombok.Data;

/**
 * @ClassName HeroWrapper
 * @Description 应用封装类
 * @Author admin
 * @Date 2024/2/20 11:36
 * @Version 1.0
 */
@Data
public class HeroWrapper {

    /***
     * 英雄
     */
    private Hero hero;

    // 仓库 或者 背包
    private Warehouse warehouse;

    public HeroWrapper(Hero hero) {
        this.hero = hero;
        warehouse = new Warehouse();
    }

    public void addExp(int fallingExp, int monsterLevel, BattleFightResult result) {
        // 找到当前职业的最高等级
        int highestLevel = getHero().getTemplate().getHighestLevel();

        if(getHero().getLevel() >= highestLevel){
            result.addConsole("已经达到当前职业模板的最高级，请转职");
            return;
        }
        // 更新英雄的经验
        int upExp = fallingExp;
        if(hero.getLevel() > (monsterLevel + 5)){
            upExp = 1;
        }else if(hero.getLevel() > (monsterLevel + 2)){
            upExp = (int) (fallingExp * 0.5);
        }

        Integer currentExp = this.hero.getCurrentExp();
        int exp = currentExp + upExp;
        this.hero.setCurrentExp(exp);
        if(this.hero.getNextLevelNeedExp() < exp){
            // 升级了
            result.addConsole("恭喜你升级了");
            hero.levelUp(exp);
        }
    }
}
